package com.imooc.bilibili.api;

import com.imooc.bilibili.api.support.UserSupport;
import com.imooc.bilibili.domain.Danmu;
import com.imooc.bilibili.domain.JsonResponse;
import com.imooc.bilibili.service.DanmuService;
import com.sun.corba.se.spi.ior.ObjectKey;
import net.bytebuddy.agent.builder.AgentBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class DanmuController {

    @Autowired
    private DanmuService danmuService;

    @Autowired
    private UserSupport userSupport;

    /**
     * 获取弹幕列表
     * @param videoId
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("danmus")
    public JsonResponse<List<Danmu>> getDanmus(@RequestParam Long videoId,
                                               String startTime,
                                               String endTime) throws ParseException {
        List<Danmu> danmuList;
        try {
            userSupport.getCurrentUserId();
            danmuList = danmuService.getDanmus(videoId,startTime,endTime);
        } catch (Exception e) {
            danmuList = danmuService.getDanmus(videoId,null,null);
        }
        return new JsonResponse<>(danmuList);
    }
}
